#include "gcpch.h"
#include "gui_styleset.h"

static geek_gui_styleset g_styleset;
geek_gui_styleset *geek_gui_styles = NULL;

static bool create_font(geek_gui_fontstyle *style)
{
    geek_gui_fontstyle full_style;
    LOGFONT lf;

    geek_gui_fontstyle_resolve(style,&full_style);
    geek_gui_fontstyle_make_logfont(&full_style,&lf);
    style->hfont = CreateFontIndirect(&lf);

    return style->hfont != NULL;
}

static void destroy_font(geek_gui_fontstyle *style)
{
    if(style->hfont != NULL)
    {
        DeleteObject(style->hfont);
        style->hfont = NULL;
    }
}

bool geek_gui_styleset_init()
{
    geek_gui_styles = &g_styleset;
    memset(geek_gui_styles,0,sizeof(geek_gui_styleset));

    geek_gui_styles->font_default.mask = geek_gui_fsmask_face|geek_gui_fsmask_height;
    wcscpy_s(geek_gui_styles->font_default.face,L"Arial");
    geek_gui_styles->font_default.height = 15;
    
    geek_gui_styles->font_listpane_items.parent = &geek_gui_styles->font_default;

    create_font(&geek_gui_styles->font_default);
    create_font(&geek_gui_styles->font_listpane_items);

    return true;
}

void geek_gui_styleset_deinit()
{
    destroy_font(&geek_gui_styles->font_listpane_items);
    destroy_font(&geek_gui_styles->font_default);

    geek_gui_styles = NULL;
}
